#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUMBER	500000
#define FORZ(i, max)	for(i = 0; i < max; i++)
#define SUM(n) ((n)*((n)+1ll)/2ll)

typedef unsigned long long int ull;

ull sum(ull i, ull j) {
	return ((j*(j+1))+(i*(i+1)))/2;
}

int main() {
	ull n,k,i,j,r;
	scanf("%llu %llu %llu %llu",&n,&k,&i,&j);
	if(k==0) {
		r=SUM(j)-SUM(i-1);
	} else {
		if(i<=k) {
			if(j<=k) {
				r=SUM(n-k+j)-SUM(n-k+i-1);
			} else {
				r=SUM(n)-SUM(n-k+i-1)+SUM(j-k);
			}
		} else {
			r=SUM(j-k)-SUM(i-k-1);
		}
	}
	printf("%llu\n",r);
	return 0;
}
